﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>潜在客户管理</title>
    <#--./表示根目录-->
    <#--../表示上一级-->
    <#include "../common/link.ftl">
    <script>
        $(function () {
            //给添加编辑按钮添加模态框
            $('.btn-input').click(function () {
                /*清除模态框数据*/
                $("#editForm input").val('');

                var json = $(this).data('json');
                if(json){//有数据代表编辑
                    $('#editForm input[name=id]').val(json.id);
                    $('#editForm input[name=name]').val(json.name);
                    $('#editForm input[name=age]').val(json.age);
                    $('#editForm select[name=gender]').val(json.gender);
                    $('#editForm input[name=tel]').val(json.tel);
                    $('#editForm input[name=qq]').val(json.qq);
                    $("#editForm select[name='job.id']").val(json.jobId);
                    $("#editForm select[name='source.id']").val(json.sourceId);
                }

                /*模态框*/
                $('#editModal').modal('show');
            });

            //提交表单,点击保存按钮
            /*$('.btn-submit').click(function () {
                $('#editForm').ajaxSubmit(function (data) {
                    window.location.reload();
                })
            });*/
            $('.btn-submit').click(function () {
                $(this).submit();
            });


            //清楚按钮
            $('.btn-delete').click(function () {
                var id = $('.btn-delete').data('id');
                $.messager.confirm('警告', '是否删除!', function() { //点击确定后的回调函数
                    $.get('/customer/delete.do?id='+id,message)
                })
            })

            //新增客户的时候，检查手机号是否已经存在，如果已经存在，则不能进行保存操作，编辑时手机号可以改但也是需要检查（参考员工用户名远程验证）
            $('#editForm').bootstrapValidator({
                feedbackIcons: { //图标
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields:{ //配置要验证的字段
                    tel:{
                        validators:{ //验证的规则
                            notEmpty:{ //不能为空
                                message:"电话必填" //错误时的提示信息
                            },
                            stringLength: { //字符串的长度范围
                                min: 1,
                                max: 12
                            },
                            remote: { //远程验证
                                type: 'POST', //请求方式
                                url: '/customer/checkTel.do', //请求地址
                                data: function() {  //自定义提交参数，默认只会提交当前用户名input的参数
                                    return {
                                        id: $('[name="id"]').val(),
                                        tel: $('[name="tel"]').val()
                                    };
                                },
                                <#if customer??>
                                      message: '请勿修改用户名', //验证不通过时的提示信息
                                </#if>
                                <#if !customer??>
                                      message: '用户名已经存在', //验证不通过时的提示信息
                                </#if>

                                delay: 1000 //输入内容2秒后发请求
                            }
                        }
                    }
                }
            }).on('success.form.bv', function() { //表单所有数据验证通过后执行里面的代码
                //提交异步表单
                /*jQueryForm方法*/
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        $.messager.alert("温馨提示","保存成功!2s后自动关闭");
                        window.setTimeout(function () {
                            window.location.href = "/customer/poolList.do";
                        },2000)
                    }else{
                        $.messager.popup(data.msg);
                    }
                })
            });

            //给修改状态按钮添加模态框
            $('.btn_changeStatus').click(function () {
                /*清除模态框数据*/
                $("#statusForm input").val('');
                var json = $(this).data('json');
                if(json){//有数据代表编辑
                    $('#statusForm input[name=id]').val(json.id);
                    $('#statusForm input[name=name]').val(json.name);
                    $('#statusForm select[name=status]').val(json.status);
                }

                /*模态框*/
                $('#statusModal').modal('show');
            });

            //提交表单,点击修改保存按钮
            $('.btn-changesubmit').click(function () {
                $('#statusForm ').ajaxSubmit(function (data) {
                    window.location.reload();
                })
            });
        });
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <#--菜单回显-->
    <#assign currentMenu="customer_pool"/>
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>潜在客户管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <div class="row" style="margin:20px">
                        <!--高级查询--->
                        <form class="form-inline" id="searchForm" action="/customer/poolList.do" method="post">
                            <input type="hidden" name="currentPage" id="currentPage" value="1">

                            <div class="form-group">
                                <label for="keyword">关键字:</label>
                                <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}" placeholder="请输入姓名/电话">

                            <@shiro.hasAnyRoles name="ADMIN,Market_Manager">
                                </div>
                                <div class="form-group">
                                    <label for="dept"> 销售人员:</label>
                                    <select class="form-control" id="seller" name="sellerId"><#--name里面的属性代表提交的参数-->
                                        <option value="-1">全部</option>
                                            <#list sellers as s>
                                                <option value="${s.id}">${s.name}</option>
                                            </#list>
                                    </select>
                                    <script>
                                        <#--$("#dept option[value='//${qo.sellerId}']").prop("selected", true);-->
                                        $('#seller').val(${qo.sellerId!});
                                    </script>
                                </div>
                            </@shiro.hasAnyRoles>

                            <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>
                        </form>
                        <!--编写内容-->
                        <div class="box-body table-responsive no-padding ">
                            <table class="table table-hover table-bordered">
                                <tr>
                                    <th>编号</th>
                                    <th>姓名</th>
                                    <th>电话</th>
                                    <th>QQ</th>
                                    <th>职业</th>
                                    <th>来源</th>
                                    <th>销售员</th>
                                    <th>状态</th>
                                    <th>录入时间</th>
                                    <th>操作</th>
                                </tr>
                        <#list pageInfo.list as customer>
                            <tr>
                                <td>${customer?index+1}</td>
                                <td>${customer.name!}</td>
                                <td>${customer.tel!}</td>
                                <td>${customer.qq!}</td>
                                <td>${(customer.job.title)!}</td>
                                <td>${(customer.source.title)!}</td>
                                <td>${(customer.seller.name)!}</td>
                                <td>${(customer.statusName)!}</td>
                                <td>${(customer.inputTime?string('yyyy-MM-dd'))!}</td>
                                <td>
                                <#--此处记得用单引号取值-->
                                    <a href="#" data-json='${customer.json!}'
                                       class="btn btn-info btn-xs btn-input">
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a href="#" data-json='${customer.json!}'
                                       class="btn btn-danger btn-xs btn_changeStatus">
                                        <span class="glyphicon glyphicon-pencil"></span> 修改状态
                                    </a>
                                </td>
                            </tr>
                        </#list>
                            </table>
                        <#--分页-->
                    <#include "../common/page.ftl">
                        </div>
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>

<#--<!-- 添加编辑模态框;-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title inputTitle">客户编辑</h4>
            </div>

            <form class="form-horizontal" action="/customer/saveOrUpdate.do" method="post" id="editForm">
                <div class="modal-body">
                    <input type="hidden" name="id">
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">客户名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name"
                                   placeholder="请输入客户姓名"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">客户年龄：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control" name="age"
                                   placeholder="请输入客户年龄"/>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">客户性别：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="gender">
                                <option value="1">男</option>
                                <option value="0">女</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">客户电话：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="tel"
                                   placeholder="请输入客户电话"/>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">客户QQ：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="qq"
                                   placeholder="请输入客户QQ"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">客户工作：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="job.id">
                                <#list jobs as j>
                                    <option value="${j.id}">${j.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">客户来源：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="source.id">
                                <#list sources as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary btn-submit" >保存</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
                </div>
            </form>
        </div>
    </div>
</div>

<#--修改状态模态框-->
<div class="modal fade" id="statusModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">修改客户状态</h4>
            </div>
            <form class="form-horizontal" action="/customer/changeStatus.do" method="post" id="statusForm">
                <div class="modal-body">
                    <input type="hidden"  name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">客户名称：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="name" name="name"
                                   placeholder="请输入客户名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">客户工作：</label>
                        <div class="col-sm-7">
                            <select class="form-control" name="status">
                                <option value="0">潜在客户</option>
                                <option value="2">开发失败客户</option>
                                <option value="4">移入入客户池</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary btn-changesubmit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>
